package com.woniu.woniu_bx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.woniu_bx.pojo.HelperCate;
import com.woniu.woniu_bx.pojo.HelperQues;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 帮助中心问答mapper接口
 *
 * @author sjy
 * @create 2022-08-27 16:19
 */
public interface HelperQuesMapper extends BaseMapper<HelperQues> {
    /**
     * 查找帮助中心问答的题目名称的数量
     *
     * @param name
     * @return
     */
    @Select("select count(*) from bx_helper_ques where name = #{name}")
    int selectNameNum(String name);
    @Select("select q.*,c.name categoryName from bx_helper_ques q,bx_helper_cate c where q.category_id=c.id and q.category_id = #{categoryId}")
    List<HelperQues> selectByCategoryId(int categoryId);

    /**
     * 查询问题以及类别
     * @param id
     * @return
     */
    @Select("select h.*,c.name cname from bx_helper_ques h,bx_helper_cate c where h.id = #{id} and c.id=h.category_id")
    @Results(id = "HelperQuesMap",value = {
            @Result(column = "cname",property = "categoryName")
    })
    HelperQues getQuesByID(int id);

    @Select("select h.*,c.name cname from bx_helper_ques h,bx_helper_cate c where c.id=h.category_id")
    @ResultMap(value = "HelperQuesMap")
    List<HelperQues> getAllQues();

    @Select("select q.name,q.answer from bx_helper_ques q,bx_helper_cate c where q.category_id = c.id")
    List<HelperQues> getQuesDetail();

    @Select("select `name`,id from bx_helper_ques")
    List<HelperQues> getAllQuesName();

    @Select("SELECT q.id,q.name FROM bx_helper_cate c,bx_helper_ques q WHERE c.id = #{cid} AND c.id = q.category_id")
    List<HelperQues> getQuesnameByCid(@Param("cid") Integer cid);
}
